﻿using System;
using System.Windows.Media.Imaging;

namespace BaseControlLibrary
{
   public static  class CommonConvert
    {
        public static BitmapImage GetImageSource(string itemPath)
        {
            if(itemPath.StartsWith(".."))
            {
                itemPath = itemPath.Substring(2).Replace("Images","Images/Tree");
            }
            BitmapImage img = new BitmapImage();
            img.BeginInit();
            img.DecodePixelHeight = 16;
            img.DecodePixelWidth = 16;
            img.CacheOption = BitmapCacheOption.OnLoad;
            img.UriSource = new Uri("pack://application:,,,/QueryResource;Component" + itemPath, UriKind.Absolute);
            img.EndInit();
            img.Freeze();
            return img;
        }
    }
}
